<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


if (!function_exists('tableJson')) {
    function tableJson($code, $msg = "error", $count = 0, $data = [], $httpStatus = 200)
    {
        $result = [
            'code'  => $code,
            'msg'   => $msg,
            'count' => $count,
            'data'  => $data,
        ];

        return json($result, $httpStatus);
    }
}

function writeJson($code, $msg = "error", $data = [], $httpStatus = 200)
{
    $result = [
        'code' => $code,
        'msg'  => $msg,
        'data' => $data,
    ];

    return json($result, $httpStatus);
}

/**
 * 生成salt
 * @param bool $num
 * @return bool|string
 */
if (!function_exists('getRandKey')) {
    function getRandKey($num = false)
    {
        if ($num) {
            $randStr = str_shuffle('1234567890');

            return substr($randStr, 0, 6);
        } else {
            return substr(md5(mt_rand(0, 32).'0905'.md5(mt_rand(0, 32)).'0123'), 10, 6);
        }
    }
}